package filmsystem.example.film.controllers;

import filmsystem.example.film.dao.FilmRepository;
import filmsystem.example.film.entities.Film;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("film")
public class FilmController {

    @Autowired
    FilmRepository filmRepository;

    @GetMapping("/new")
    public String displayFilmForm(Model model){

        Film aFilm = new Film();
        model.addAttribute("film",aFilm);
        return "admin/new-film";
    }

    @PostMapping("/save")
    public String createFilm(Model model,Film film){

        filmRepository.save(film);
        return "redirect:/film/new";
    }
}
